<?php
	require($path_prefix.$settings['sitemap']);

	function get_nav($sitemap, $path=""){
		global $page;
		$current_page = (isset($page) ? $page : '');
		$nav = '';
		if(isset($sitemap)){
			$nav = "<ul>\r\n";
			foreach($sitemap as $k=>$entry){
				$nav .= '<li class="'.$entry['slug'].'">'.(($entry['slug'] != $current_page) ? '<a href="'.($entry['slug'] != 'home' ? $path.'/'.$entry['slug'] : '').'/">' : '<strong>').$entry['title'].(($entry['slug'] != $current_page) ? '</a>' : '</strong>');
				if(isset($entry['sitemap'])){ $nav .= get_nav($entry['sitemap'], $path.'/'.$entry['slug']); }
				$nav .= "</li>\r\n";
			}
			$nav .= "</ul>\r\n";
		}
		return($nav);
	}
	
	function get_sitemap_by_slug($sitemap, $slug){
		return $sitemap[get_entry_by_slug($sitemap, $slug)]['sitemap'];
	}
	
	function get_entry_by_slug($sitemap, $slug){
		foreach($sitemap as $k=>$page){
			if($page['slug'] == $slug){ return $k; }
			if(isset($page['sitemap'])){
				$k2 = get_entry_by_slug($page['sitemap'], $slug);
				if($page['sitemap'][$k2]['slug'] == $slug){ return $k; }
			}
		}
		return false;
	}
	
	function get_title_by_slug($sitemap, $slug){
		foreach($sitemap as $page){
			if($page['slug'] == $slug){ return $page['title']; }
			if(isset($page['sitemap'])){ 
				$title = get_title_by_slug($page['sitemap'], $slug);
				if($title != false){ return $page['title'].' :: '.$title; }
			}
		}
		return false;
	}
?>